package com.example.exception;

/**
 * 参数验证异常类
 * 用于处理参数验证相关的异常
 */
public class ValidationException extends BaseException {
    
    public ValidationException(String errorCode, String errorMessage) {
        super(errorCode, errorMessage, ErrorCategory.VALIDATION);
    }
    
    public ValidationException(String errorCode, String errorMessage, Object errorDetails) {
        super(errorCode, errorMessage, errorDetails);
        setErrorCategory(ErrorCategory.VALIDATION);
    }
    
    // ========== 参数验证异常 ==========
    
    public static ValidationException parameterError() {
        return new ValidationException(ErrorCode.PARAMETER_ERROR, "参数错误");
    }
    
    public static ValidationException parameterError(String parameterName) {
        return new ValidationException(ErrorCode.PARAMETER_ERROR, "参数错误: " + parameterName);
    }
    
    public static ValidationException parameterMissing(String parameterName) {
        return new ValidationException(ErrorCode.PARAMETER_ERROR, "缺少必需参数: " + parameterName);
    }
    
    public static ValidationException parameterInvalid(String parameterName, String reason) {
        return new ValidationException(ErrorCode.PARAMETER_ERROR, 
            String.format("参数 %s 无效: %s", parameterName, reason));
    }
    
    public static ValidationException dataValidationFailed(String message) {
        return new ValidationException(ErrorCode.DATA_VALIDATION_FAILED, "数据验证失败: " + message);
    }
    
    public static ValidationException dataValidationFailed(String field, String message) {
        return new ValidationException(ErrorCode.DATA_VALIDATION_FAILED, 
            String.format("字段 %s 验证失败: %s", field, message));
    }
}
